﻿using System;
using System.Collections.Generic;

namespace FrameDesign.FrameWork
{
    public class IOCContainer
    {
        /// <summary>
        /// 实例
        /// </summary>
        public Dictionary<Type, object> m_Instances = new Dictionary<Type, object>();
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="instance"></param>
        /// <typeparam name="T"></typeparam>
        public void Register<T>(T instance)
        {
            var key = typeof(T);
            m_Instances[key] = instance;
        }
        /// <summary>
        /// 获取
        /// </summary>
        public T Get<T>() where T: class
        {
            var key = typeof(T);
            if (m_Instances.TryGetValue(key, out var resObj))
            {
                return resObj as T;
            }
            return null;
        }

    }
}